def number_up_down(list, indent=True, ):
    a = []
    b = []
    num = 0
    s_num = 0
    for ascii in list:
        listLength = len(list)  # 记录列表的长度
        a.append(ord(ascii))  # 将字符转换成ascii码
        if type(ascii) == int:  # 判断列表内字符是否为int类型
            num = num + 1  # 记录个数
        elif type(ascii) == str:  # 判断列表内字符是否为str类型
            s_num = s_num + 1  # 记录个数
    if num == listLength:  # 判断列表内所有都为数字类型，进入排序阶段
        while listLength > 0:  # 冒泡法排序
            for i in range(listLength - 1): #后续采用一个比较特殊的方法
                if list[i] > list[i + 1]:
                    list[i] = list[i] + list[i + 1]
                    list[i + 1] = list[i] - list[i + 1]
                    list[i] = list[i] - list[i + 1]
            listLength = listLength - 1
        if indent == False:  # 倒序排列
            list.reverse()
            print(list)
        else:  # 正序排列
            print(list)

    if s_num==listLength:  # 判断列表內所有都为字符类型，进入排序
        while listLength > 0:
            for i in range(listLength - 1):
                if list[i] > list[i + 1]:
                    a[i], a[i + 1] = a[i + 1], a[i]  # 此定义方式类似于 t=(b,a+b) a=t[0] b=t[1]的形式
            listLength -= 1
        for ascii2 in a:
            b.append(chr(ascii2))
        if indent == False:
            b.reverse()
            print(b)
        else:
            print(b)


list = ["a", "z", 'c', 'q', 'p']
number_up_down(list, False)
